package com.meiyu.live.ui.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.meiyu.live.BaseActivity;
import com.meiyu.live.R;
import com.meiyu.live.comm.UserConfig;
import com.meiyu.live.popj.ActiveInfo;
import com.meiyu.live.widget.ShareDialog;

/**
 * Created by zbl on 2016/9/22.
 */
public class EventActivity extends BaseActivity implements View.OnClickListener {

    private WebView wv_event;
    private View btn_back, btn_share;
    private TextView tv_title;
    private ShareDialog shareDialog;
    private static ActiveInfo activeInfo;

    public static void start(Context context, ActiveInfo info) {
        activeInfo = info;
        context.startActivity(new Intent(context, EventActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evnet);
        init();
    }

    private void init() {
        btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText(activeInfo.getName());
        btn_share = findViewById(R.id.btn_share);
        btn_share.setOnClickListener(this);
        wv_event = (WebView) findViewById(R.id.wv_event);
        //设置WebView属性，能够执行Javascript脚本
        wv_event.getSettings().setJavaScriptEnabled(true);
        wv_event.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        //加载需要显示的网页
        wv_event.loadUrl(activeInfo.getWebUrl() + "?channel=2");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_share:
                if (shareDialog == null) {
                    shareDialog = new ShareDialog(this, activeInfo.getName(), activeInfo.getNote(), activeInfo.getPrivateUrl(), activeInfo.getWebUrl() + "?u=" + UserConfig.getInstance().getPersonalInfo().getUnique_id());
                }
                shareDialog.show();
                break;
        }
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    public void onError() {
        super.onError();
    }
}
